package com.qin.EducationalManger.user.service;

import java.util.ArrayList;
import java.util.List;

import com.qin.EducationalManger.user.dao.UserDao;
import com.qin.EducationalManger.user.model.UserModel;

public class UserService {

	public String insert(UserModel model,String password,String teacherId) {

		String content = "";

		UserDao userDao = new UserDao();

		List<UserModel> models = new ArrayList<>();

		models = userDao.select(model); //只查账号，是否存在

		if (models.isEmpty()) {

			model.setPassword(password);   //不存在 再把密码 和 教师id写进去
			model.setTeacherId(teacherId);
			int num = userDao.insert(model);
			if (num == 1) {
				content = "注册成功";
			} else {
				content = "注册失败";
			}

		} else {
			content = "对不起，该账户已经存在了";
		}

		return content;
	}

	public String select(UserModel model, String password) {

		String content = "";
		UserDao userDao = new UserDao();
       
		
		List<UserModel> models = userDao.select(model);
		   
		if (models.isEmpty() == false) {
		
			if (password.equals(models.get(0).getPassword())) {
				content = "登录成功";
			} else {
				content = "登陆失败，密码错误";
			}
		} else {
			content = "登陆失败,该账号不存在";

		}
		return content;

	}

}
